<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Goods extends Model
{

    const TABLE_NAME = 'goods';

    protected $table = self::TABLE_NAME;

    public function setGoodsDescImageAttribute($pictures)
    {
        if (is_array($pictures)) {
            $this->attributes['goods_desc_image'] = json_encode($pictures);
        }
    }

    public function getGoodsDescImageAttribute($pictures)
    {
        if($pictures){
            return json_decode($pictures, true);
        }
        return [];
    }

    public function goods_sku()
    {
        return $this->hasMany(GoodsSku::class,'goods_id','id');
    }

}